using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VQGKREGEL
    {
        public DataRow Convert2QGKREGEL(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryQGKREGEL(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["QGRMANDANT"] = " ".PadRight(2 ); 
         dwReturn["QGRGKREGEL"] = " ".PadRight(8 ); 
         dwReturn["QGRAENZL"] = " ".PadRight(0 ); 
         dwReturn["QGRAENB"] = " ".PadRight(8 ); 
         dwReturn["QGRAEND"] = " ".PadRight(0 ); 
         dwReturn["QGRNEUB"] = " ".PadRight(8 ); 
         dwReturn["QGRNEUD"] = " ".PadRight(0 ); 
         dwReturn["QGRBEZ"] = " ".PadRight(30 ); 
         dwReturn["QGRSTATUS"] = " ".PadRight(1 ); 
         dwReturn["QGRWAKZ"] = " ".PadRight(1 ); 
         dwReturn["QGRKUNDE"] = " ".PadRight(8 ); 
         dwReturn["QGRWRK"] = " ".PadRight(3 ); 
         dwReturn["QGRABTL"] = " ".PadRight(3 ); 
         dwReturn["QGRART"] = " ".PadRight(20 ); 
         dwReturn["QGRVAR"] = " ".PadRight(2 ); 
         dwReturn["QGRFARBE"] = " ".PadRight(10 ); 
         dwReturn["QGRDESSIN"] = " ".PadRight(10 ); 
         dwReturn["QGRCOLORIT"] = " ".PadRight(10 ); 
         dwReturn["QGRBESCH"] = " ".PadRight(10 ); 
         dwReturn["QGRPROGRP"] = " ".PadRight(3 ); 
         dwReturn["QGRARTGRP"] = " ".PadRight(3 ); 
         dwReturn["QGRVKUNDE"] = " ".PadRight(8 ); 
         dwReturn["QGRVB"] = " ".PadRight(3 ); 
         dwReturn["QGRVG"] = " ".PadRight(3 ); 
         dwReturn["QGRBRANCHE"] = " ".PadRight(3 ); 
         dwReturn["QGRABNGRP"] = " ".PadRight(3 ); 
         dwReturn["QGRLAND"] = " ".PadRight(3 ); 
         dwReturn["QGRKOLL"] = " ".PadRight(4 ); 
         dwReturn["QGRVART"] = " ".PadRight(24 ); 
         dwReturn["QGRVFARBE"] = " ".PadRight(10 ); 
         dwReturn["QGRVDESS"] = " ".PadRight(1 ); 
         dwReturn["QGRFKATALOG"] = " ".PadRight(3 ); 
         dwReturn["QGRFILLER"] = " ".PadRight(35 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapQGKREGEL(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveQGKREGEL(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryQGKREGEL(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapQGKREGEL(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertQGKREGEL(dwLocal, ITXDBVERSION);
            }
            UpdateQGKREGEL(dwLocal);
        }
        public void InsertQGKREGEL(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO QGKREGEL(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryQGKREGEL(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM QGKREGEL WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM QGKREGEL  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "QGKREGEL";
            Return = Result;
            return Return;
        }
        public void DeleteQGKREGEL(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM QGKREGEL   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateQGKREGEL(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE QGKREGEL SET "
                    +"QGRMANDANT= :QGRMANDANT,"
                    +"QGRGKREGEL= :QGRGKREGEL,"
                    +"QGRAENZL= :QGRAENZL,"
                    +"QGRAENB= :QGRAENB,"
                    +"QGRAEND= :QGRAEND,"
                    +"QGRNEUB= :QGRNEUB,"
                    +"QGRNEUD= :QGRNEUD,"
                    +"QGRBEZ= :QGRBEZ,"
                    +"QGRSTATUS= :QGRSTATUS,"
                    +"QGRWAKZ= :QGRWAKZ,"
                    +"QGRKUNDE= :QGRKUNDE,"
                    +"QGRWRK= :QGRWRK,"
                    +"QGRABTL= :QGRABTL,"
                    +"QGRART= :QGRART,"
                    +"QGRVAR= :QGRVAR,"
                    +"QGRFARBE= :QGRFARBE,"
                    +"QGRDESSIN= :QGRDESSIN,"
                    +"QGRCOLORIT= :QGRCOLORIT,"
                    +"QGRBESCH= :QGRBESCH,"
                    +"QGRPROGRP= :QGRPROGRP,"
                    +"QGRARTGRP= :QGRARTGRP,"
                    +"QGRVKUNDE= :QGRVKUNDE,"
                    +"QGRVB= :QGRVB,"
                    +"QGRVG= :QGRVG,"
                    +"QGRBRANCHE= :QGRBRANCHE,"
                    +"QGRABNGRP= :QGRABNGRP,"
                    +"QGRLAND= :QGRLAND,"
                    +"QGRKOLL= :QGRKOLL,"
                    +"QGRVART= :QGRVART,"
                    +"QGRVFARBE= :QGRVFARBE,"
                    +"QGRVDESS= :QGRVDESS,"
                    +"QGRFKATALOG= :QGRFKATALOG,"
                    +"QGRFILLER= :QGRFILLER,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("QGRMANDANT", OracleType.NVarChar).Value = dwData["QGRMANDANT"].ToString(); 
          or1.Parameters.Add("QGRGKREGEL", OracleType.NVarChar).Value = dwData["QGRGKREGEL"].ToString(); 
          or1.Parameters.Add("QGRAENZL", OracleType.NVarChar).Value = dwData["QGRAENZL"].ToString(); 
          or1.Parameters.Add("QGRAENB", OracleType.NVarChar).Value = dwData["QGRAENB"].ToString(); 
          or1.Parameters.Add("QGRAEND", OracleType.NVarChar).Value = dwData["QGRAEND"].ToString(); 
          or1.Parameters.Add("QGRNEUB", OracleType.NVarChar).Value = dwData["QGRNEUB"].ToString(); 
          or1.Parameters.Add("QGRNEUD", OracleType.NVarChar).Value = dwData["QGRNEUD"].ToString(); 
          or1.Parameters.Add("QGRBEZ", OracleType.NVarChar).Value = dwData["QGRBEZ"].ToString(); 
          or1.Parameters.Add("QGRSTATUS", OracleType.NVarChar).Value = dwData["QGRSTATUS"].ToString(); 
          or1.Parameters.Add("QGRWAKZ", OracleType.NVarChar).Value = dwData["QGRWAKZ"].ToString(); 
          or1.Parameters.Add("QGRKUNDE", OracleType.NVarChar).Value = dwData["QGRKUNDE"].ToString(); 
          or1.Parameters.Add("QGRWRK", OracleType.NVarChar).Value = dwData["QGRWRK"].ToString(); 
          or1.Parameters.Add("QGRABTL", OracleType.NVarChar).Value = dwData["QGRABTL"].ToString(); 
          or1.Parameters.Add("QGRART", OracleType.NVarChar).Value = dwData["QGRART"].ToString(); 
          or1.Parameters.Add("QGRVAR", OracleType.NVarChar).Value = dwData["QGRVAR"].ToString(); 
          or1.Parameters.Add("QGRFARBE", OracleType.NVarChar).Value = dwData["QGRFARBE"].ToString(); 
          or1.Parameters.Add("QGRDESSIN", OracleType.NVarChar).Value = dwData["QGRDESSIN"].ToString(); 
          or1.Parameters.Add("QGRCOLORIT", OracleType.NVarChar).Value = dwData["QGRCOLORIT"].ToString(); 
          or1.Parameters.Add("QGRBESCH", OracleType.NVarChar).Value = dwData["QGRBESCH"].ToString(); 
          or1.Parameters.Add("QGRPROGRP", OracleType.NVarChar).Value = dwData["QGRPROGRP"].ToString(); 
          or1.Parameters.Add("QGRARTGRP", OracleType.NVarChar).Value = dwData["QGRARTGRP"].ToString(); 
          or1.Parameters.Add("QGRVKUNDE", OracleType.NVarChar).Value = dwData["QGRVKUNDE"].ToString(); 
          or1.Parameters.Add("QGRVB", OracleType.NVarChar).Value = dwData["QGRVB"].ToString(); 
          or1.Parameters.Add("QGRVG", OracleType.NVarChar).Value = dwData["QGRVG"].ToString(); 
          or1.Parameters.Add("QGRBRANCHE", OracleType.NVarChar).Value = dwData["QGRBRANCHE"].ToString(); 
          or1.Parameters.Add("QGRABNGRP", OracleType.NVarChar).Value = dwData["QGRABNGRP"].ToString(); 
          or1.Parameters.Add("QGRLAND", OracleType.NVarChar).Value = dwData["QGRLAND"].ToString(); 
          or1.Parameters.Add("QGRKOLL", OracleType.NVarChar).Value = dwData["QGRKOLL"].ToString(); 
          or1.Parameters.Add("QGRVART", OracleType.NVarChar).Value = dwData["QGRVART"].ToString(); 
          or1.Parameters.Add("QGRVFARBE", OracleType.NVarChar).Value = dwData["QGRVFARBE"].ToString(); 
          or1.Parameters.Add("QGRVDESS", OracleType.NVarChar).Value = dwData["QGRVDESS"].ToString(); 
          or1.Parameters.Add("QGRFKATALOG", OracleType.NVarChar).Value = dwData["QGRFKATALOG"].ToString(); 
          or1.Parameters.Add("QGRFILLER", OracleType.NVarChar).Value = dwData["QGRFILLER"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
